#include "main.h"

CSprite::CSprite(LPDIRECT3DDEVICE9 _device,  LPCSTR _filename, int _frames, int _speed){
	texture=NULL;
	count=1;
	if (_frames == NULL){_frames=1;}
	if (_speed == NULL){speed=1;}

	if (_frames<1){_frames=1;}
	frames = _frames;

	if (_speed<1){_speed=1;}
	speed = (float)_speed;

	imgspeed = 0;
	
	if (SUCCEEDED(D3DXCreateTextureFromFile(_device, _filename, &texture))){
		
		D3DXGetImageInfoFromFile(_filename, &imginfo);
		width = (float)imginfo.Width/frames;
		height = (float)imginfo.Height;
		center.x = width/2;
		center.y = height/2;
		center.z = 0.0f;
	}

	xtile = (int)width;

}
CSprite::CSprite(LPDIRECT3DDEVICE9 _device,  LPCSTR _filename, D3DXVECTOR3 _transparency, int _frames, int _speed){
	texture=NULL;
	count=1;

	if (_frames<1){_frames=1;}
	frames = _frames;

	if (_speed<1){_speed=1;}
	speed = (float)_speed;

	imgspeed = 0;

	if (SUCCEEDED(D3DXCreateTextureFromFileExA(_device, _filename, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, NULL,
		D3DFMT_UNKNOWN,D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB((int)_transparency.x,(int)_transparency.y,(int)_transparency.z),
		NULL, NULL, &texture))){
		D3DXGetImageInfoFromFile(_filename, &imginfo);
		width = (float)imginfo.Width/frames;
		height = (float)imginfo.Height;
		center.x = width/2;
		center.y = height/2;
		center.z = 0.0f;
	}

	xtile = (int)width;

}

CSprite::CSprite(LPDIRECT3DDEVICE9 _device,  LPCSTR _filename, D3DXVECTOR3 _transparency, int _xframes, int _yframes, int _speed){
	texture=NULL;
	count=1;
	frames = 0;

	if (_speed<1){_speed=1;}
	speed = (float)_speed;

	imgspeed = 0;

	if (SUCCEEDED(D3DXCreateTextureFromFileExA(_device, _filename, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, NULL,
		D3DFMT_UNKNOWN,D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB((int)_transparency.x,(int)_transparency.y,(int)_transparency.z),
		NULL, NULL, &texture))){
		D3DXGetImageInfoFromFile(_filename, &imginfo);
		width = (float)imginfo.Width/_xframes;
		height = (float)imginfo.Height/_yframes;
		center.x = width/2;
		center.y = height/2;
		center.z = 0.0f;
	}

	xtile = (int)width;
	ytile = (int)height;

}
CSprite::~CSprite(){
	if(texture)
		texture->Release();
	texture=NULL;
}

